<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>扩展卡</title>
    <link rel="stylesheet" href="./css/style.css">
    <script src="./js/setRem.js"></script>
</head>
<body>
    <div class="container">
        <div class="item active"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
    </div>

    <script>
        var myApp = {
            getDom: (function () {
                var items = document.querySelectorAll(".item");

                return {
                    items: items
                }
            })(),
            methods: {
                cli: function () {
                    var items = myApp.getDom.items;
                    //循环所有的items
                    items.forEach(function (item) {
                        item.onclick = function () {
                            //去除所有的active
                            for (var i = 0; i < items.length; i++) {
                                items[i].classList.remove("active");
                            }
                            //给当前点击的添加active
                            this.classList.add("active");
                        }
                    })
                }
            }
        }

        //调用方法
        myApp.methods.cli();
    </script>
</body>
</html>